package main

import (
	"github.com/gin-gonic/gin"
	"github.com/loopfz/gadgeto/tonic"
	"github.com/wI2L/fizz"
	"log"
	"net/http"
	"strconv"
)

func main() {
	engine := gin.Default()

	fizz := fizz.NewFromEngine(engine)

	// all routes registered on group bar will have
	// a relative path starting with /foo/bar
	bar := fizz.Group("/bar", "Bar", "Bar group")

	// /foo/bar/{barID}
	bar.GET("/:barID", nil, tonic.Handler(func(ctx *gin.Context) {
		rs := []byte("dafafdasfaf")

		ctx.Status(http.StatusOK)
		ctx.Header("content-type", "application/json;charset=UTF-8")
		ctx.Header("content-length", strconv.Itoa(len(rs)))
		ctx.Header("connection", "keep-alive")

		_, err := ctx.Writer.Write(rs)
		if nil != err {
			log.Fatal(err)
			return
		}

		ctx.Writer.Flush()
	}, 200))

	srv := &http.Server{
		Addr:    ":4242",
		Handler: fizz,
	}
	srv.ListenAndServe()

}
